﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LogicUniversityBiz;

namespace LogicUniversity.clerks
{
    public partial class RecordStockCard : System.Web.UI.Page
    {
        private CoreClerkFascade fs = new CoreClerkFascade();
        protected void Page_PreInit(Object sender, EventArgs e)
        {
            //(Session["Role"]
            if (Session["Role"] as string != "Clerk")
            {
                Response.Redirect("~/Login.aspx");
            }

        }
        private void initLabel()
        {
            lblItemCode.Text = "Item Code";
            lblDesc.Text = "Description";
            lblBin.Text = "Bin";
            lblMeasurement.Text = "Measurement";
        }

        public void fillItemInfo(string  itemCode)
        {
            Catelogue c = fs.getItemInfoOf(itemCode);
            ItemCode.Text = c.Item_Code;
            Desc.Text = c.Item_Description;
            Bin.Text = c.Bin.ToString();
            UOM.Text = c.Measurement;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                fillDataGrid();
            }

        }
        public void fillDataGrid()
        {
            List<string> itemCodes = fs.getAllItemCode();
            ddlItemCode.DataSource = itemCodes;
            ddlItemCode.DataBind();
            string itemCode = ddlItemCode.SelectedValue.Trim().ToString();

            List<Stock_Card_Detail> ls = fs.getStockInfoOf(itemCode);
            GridView1.DataSource = ls;
            GridView1.DataBind();

            initLabel();
            fillItemInfo(itemCode);
        }

        protected void btnFilter_Click(object sender, EventArgs e)
        {
            string itemCode = ddlItemCode.SelectedValue.Trim();
            List<Stock_Card_Detail> detail;
            if (txtDate.Text.Trim() == null || txtDate.Text.Trim() == "")
            {
                detail = fs.getStockInfoOf(itemCode);
            }
            else
            {
                DateTime date=DateTime.Parse(txtDate.Text.Trim());
                detail = fs.getStockInfoOf(itemCode, date);
            }

            GridView1.DataSource = detail;
            GridView1.DataBind();
            fillItemInfo(itemCode);
        }
    }
}